import axios from "axios";
import { Message } from "element-ui";

// 基础配置
const service = axios.create({
    baseURL: 'api',
    timeout: 5000
})

// 请求拦截器
service.interceptors.request.use(
    conf => {
        return conf;
    },
);

// 响应拦截器
service.interceptors.response.use(
    conf => {
        return conf.data;
    }, err => {
        Message({
            message: err ? err.response.data.message : "网络错误",
            type: "error",
            duration: 1500
        })
        return { code: 400, data: "" }
    }
);

// 导出
export default service;